package com.java.Listener;

import javax.servlet.ServletContext;
import javax.servlet.annotation.WebListener;
import javax.servlet.http.*;
import java.util.ArrayList;

/**
 * @ClassName SessionListener
 * @Description session监听器
 * @Author 0715-YuHao
 * @Date 2020/9/12 15:08
 */
@WebListener
public class SessionListener implements HttpSessionListener {
    @Override
    public void sessionCreated(HttpSessionEvent httpSessionEvent) {
    }

    @Override
    public void sessionDestroyed(HttpSessionEvent httpSessionEvent) {
//        HttpSession session = httpSessionEvent.getSession();
//        ServletContext application = session.getServletContext();
//        ArrayList<String> loginList = (ArrayList<String>) application.getAttribute("loginList");
//        String username = (String) session.getAttribute("adminUsername");
//        String userPhone = (String) session.getAttribute("userPhone");
//        if (username != null) {
//            loginList.remove(username);
//            application.setAttribute("loginList", loginList);
//        }
//        if (userPhone != null) {
//            loginList.remove(userPhone);
//            application.setAttribute("loginList", loginList);
//        }
    }
}
